#!/usr/bin/env python
# encoding: utf-8
#@author: jack
#@contact: 935650354@qq.com
#@site: https://www.cnblogs.com/jackzz


import re
import time
import random
import requests
from PIL import Image
from  selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from  selenium.webdriver.support import expected_conditions as EC
from  selenium.webdriver.common.by import By
from  io import BytesIO
from selenium.webdriver.common.action_chains import ActionChains



from utils.SliderImage import SliderImage

if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('http://www.cnbaowen.net/api/geetest/')
    try:
        count = 5
        # waiting slidingVC loading
        wait = WebDriverWait(driver, 10)
        element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'gt_slider_knob')))
        while count >0:
            SliderImage().main(driver,element)
            try:
                succes = wait.until(EC.presence_of_all_elements_located((By.XPATH,'//div[@class="gt_ajax_tip gt_success"]')))
                if succes:
                    print('恭喜你！识别成功...')
                    break
            except Exception as e:
                print('识别错误，继续')
                count -=1
    finally:
        driver.quit()

